﻿/**
 * Proyecto: Cognitum
 * Global IT Services 2008
 * @author Mislas
 */
/* ENDOSOS TIPO A */
Cognitum.Polizas.Endoso.PoolA.Gmm.Editor = Ext.extend(Cognitum.Polizas.Endoso.Editor, {

    ramoClave: '1',
    
    esFlotilla: true,
    
    initComponent: function(){
        Ext.apply(this, {
            seccionesAdicionales: [{
                title: 'Incisos',
                items: [{
                    xtype: 'ag.list',
                    hideLabel: true,
                    entityName: 'Certificados',
                    name: 'Movimientos',
                    context: 'm.EndosoAlta.Id=?',
                    anchor: '99% 99%',
					updateControls: function(value){
						if(Ext.isEmpty(value)) {
							return;
						}
						// menu config
						this.canUpdate= !(this.canUpdate && value.EstatusEndoso == 0);
						this.deleteMenuAction.setDisabled(!(this.canDelete && value.EstatusEndoso == 0));
						this.newMenuAction.setDisabled(!(this.canNew && value.EstatusEndoso == 0));
						this.newToolbarButton.setDisabled(!(this.canNew && value.EstatusEndoso == 0));
					}
                }]
            }]
        });
        Cognitum.Polizas.Endoso.PoolA.Gmm.Editor.superclass.initComponent.apply(this, arguments);
    }
});
Ext.reg('end.gmm.poola.editor', Cognitum.Polizas.Endoso.PoolA.Gmm.Editor);

/* ENDOSOS TIPO D */
Cognitum.Polizas.Endoso.PoolD.Gmm.Editor = Ext.extend(Cognitum.Polizas.Endoso.Editor, {

    ramoClave: '1',
    
    esFlotilla: true,
    
    initComponent: function(){
        Ext.apply(this, {
            seccionesAdicionales: [{
                title: 'Incisos',
                items: [{
                    xtype: 'entity.list',
                    hideLabel: true,
                    entityName: 'Certificados',
                    name: 'Movimientos',
                    context: 'm.EndosoBaja.Id=?',
                    anchor: '99% 99%',
					selectionConfig: {
						multiSelect: true
					},
					updateControls: function(value){
						if(Ext.isEmpty(value)) {
							return;
						}
						// menu config
						this.deleteMenuAction.setDisabled(!(this.canDelete && value.EstatusEndoso == 0));
						this.newToolbarButton.setDisabled(!(this.canNew && value.EstatusEndoso == 0));
					},
					getSelectContextSubQuery: function(endoso) {
				        if (PLOG.isDebugEnabled()) {
				            PLOG.debug('[EntityList.onBeforeAdd] <-' + endoso);
				        }
						if(!Ext.isEmpty(endoso) && !Ext.isEmpty(endoso.Poliza)) {
							return 'a.Estatus=1 and a.Poliza.Id=' + endoso.Poliza.Id;
						}
					},
					onBeforeAdd: function(id, data, endoso) {
				        if (PLOG.isDebugEnabled()) {
				            PLOG.debug('[EntityList.onBeforeAdd] <-' + endoso);
				        }
						if(Ext.isEmpty(endoso)) {
							return;
						}
						this.entity.useInvoker('DoAsignaEndosoBaja', 
							[ id, endoso.Id ], {
							fn: function() {
								this.reload();
							}, scope: this
						});
					},
					onBeforeDelete: function(id, data, endoso) {
				        if (PLOG.isDebugEnabled()) {
				            PLOG.debug('[EntityList.onBeforeDelete] <-' + endoso);
				        }
						if(Ext.isEmpty(endoso)) {
							return;
						}
						this.entity.useInvoker('DoDesasignaEndosoBaja', id, {
							fn: function() {
								this.reload();
							}, scope: this
						});
					}
                }]
            }]
        });
        Cognitum.Polizas.Endoso.PoolD.Gmm.Editor.superclass.initComponent.apply(this, arguments);
    }
});
Ext.reg('end.gmm.poold.editor', Cognitum.Polizas.Endoso.PoolD.Gmm.Editor);
